package com.hdu.careerplan.util;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hdu.careerplan.mapper.UserMapper;
import com.hdu.careerplan.pojo.entity.User;

import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class PasswordUtil {
    private static final String SALT = "wiueiwq902jmdsknpo02";  // 加盐混淆

    /**
     * 加密密码
     *
     * @param password 密码
     * @return 加密后的密码
     */
    public static String encryptPassword(String password) {
        MessageDigest md;
        try {
            md = MessageDigest.getInstance("SHA");
        } catch (NoSuchAlgorithmException e) {
            throw new RuntimeException(e);
        }
        byte[] digest = md.digest((SALT + password).getBytes());
        BigInteger bigInteger = new BigInteger(1, digest);
        return bigInteger.toString(16);
    }
}
